import fisheye_consts

class MessageQueue:
    """
    A class which is responsible for holding the packets received by each node.
    """
    def __init__(self):
        """
        Constructor.
        """
        self._capacity = fisheye_consts.FISHEYE_MESSAGE_QUEUE_CAPACITY
        self._queue = []
        
    def append(self, packet):
        """
        Appends a packet to the message quque. (to the beginning of the queue)
        """
        if len(self._queue) < self._capacity:
            self._queue.append(packet)
            return True
        else:
            print "Cannot hold more packets in the queue"
            return False
    
    def remove(self, packet):
        """
        Removes a packet from the queue.
        """
        if packet in self._queue:
            self._queue.remove(packet)
            
    def get_packets(self):
        """
        Returns a copy of the queue.
        """
        return self._queue[:]
        
    def __repr__(self):
        return str(self._queue)
        
